package com.vip.fdfs.controller;

import com.vip.common.constant.UrlConsts;
import com.vip.common.response.RestResponse;
import com.vip.common.response.RestResponses;
import com.vip.fdfs.dto.GetFileDTO;
import com.vip.fdfs.service.IFileBaseInfoService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 文件信息控制器
 *
 * @author wgb
 * @date 2019/12/22 17:34
 */
@Slf4j
@RestController
@RequestMapping(value = UrlConsts.API + "/file/base")
public class FileBaseInfoController {
    @Autowired
    private IFileBaseInfoService fileBaseInfoService;

    /**
     * 获取文件列表
     *
     * @return
     */
    @GetMapping(value = "/list")
    public RestResponse<List<GetFileDTO>> getFileList(@RequestParam Integer pageNo, @RequestParam Integer pageSize, @RequestParam(required = false) String fileName
          , @RequestParam(required = false) Long startTime, @RequestParam(required = false) Long endTime, @RequestParam(required = false) Boolean isDel) {
        return RestResponses.newResponseFromResult(fileBaseInfoService.getFileInfoList(pageNo, pageSize, fileName, startTime, endTime, isDel));
    }

    /**
     * 获取文件详情
     *
     * @param fileId 文件ID
     * @return
     */
    @GetMapping(value = "/{fileId}")
    public RestResponse<GetFileDTO> getFileDetails(@PathVariable("fileId") String fileId) {
        return RestResponses.newResponseFromResult(fileBaseInfoService.getFileDetails(fileId));
    }

    /**
     * 更新指定文件备注
     *
     * @param fileId 文件ID
     * @return
     */
    @PutMapping(value = "/{fileId}")
    public RestResponse<String> updateFileRemark(@PathVariable("fileId") String fileId, @RequestBody String description) {
        return RestResponses.newResponseFromResult(fileBaseInfoService.updateFileRemark(fileId, description));
    }

}
